import 'package:shared_preferences/shared_preferences.dart';

class SearchHistory{
static  void  saveKeyWord(String keyword) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    List<String> list = prefs.getStringList(keyword);
    if(list==null){
      list=[];
    }
    list.add(keyword);
    if (list.length > 20) {
      list.removeAt(list.length - 1);
    }
    await prefs.setStringList('searchLists', list);
  }


static Future<List<String>> getKeyWords() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getStringList("searchLists");
  }

static void clearKeyWords(String keyword) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    await prefs.setStringList('searchLists', []);
  }

}